package com.frank.im.base;

import java.net.URI;

import org.java_websocket.client.WebSocketClient;
import org.java_websocket.drafts.Draft;
import org.java_websocket.framing.Framedata;
import org.java_websocket.handshake.ServerHandshake;

/**
 * im类
 * 
 * @author Frank
 * @version 1.0 Create by 2016.4.8
 */
public class ImClient extends WebSocketClient {
	private Imable imable = null;

	public ImClient(URI serverUri, Draft draft) {
		super(serverUri, draft);
	}

	public ImClient(URI serverURI) {
		super(serverURI);
	}

	public void setImable(Imable imable) {
		this.imable = imable;
	}

	@Override
	public void onOpen(ServerHandshake handshakedata) {
		if (imable != null) {
			imable.onOpen(handshakedata);
		}
	}

	@Override
	public void onMessage(String message) {
		if (imable != null) {
			imable.onMessage(message);
		}
	}

	@Override
	public void onFragment(Framedata fragment) {
		if (imable != null) {
			imable.onFragment(fragment);
		}
	}

	@Override
	public void onClose(int code, String reason, boolean remote) {
		if (imable != null) {
			imable.onClose(code, reason, remote);
		}
	}

	@Override
	public void onError(Exception ex) {
		if (imable != null) {
			imable.onError(ex);
		}
	}

}